package com.frank.Test;

import com.frank.globalException.exception.MyException;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.Assert;

import java.io.File;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.stream.Stream;

import static com.frank.globalException.domain.EnumError.BAD_REQUEST;
import static com.frank.globalException.domain.EnumError.SERVER_ERROR;

/**
 * @author 小石潭记
 * @date 2020/10/23 14:46
 * @Description: ${todo}
 */
public class Test {

    public static void main(String[] args) {
        /*LocalDate beginDateTime = LocalDate.parse("20201010", DateTimeFormatter.BASIC_ISO_DATE);
        System.out.println(beginDateTime);
        LocalDate date = LocalDate.parse("20150131", DateTimeFormatter.BASIC_ISO_DATE);
        System.out.println(date);

        String ab = "" +
                "\"name\": \"cxb\"\n" +
                "\"age\" : \"10\" " +
                "";
        System.out.println(ab);

        // 直接抛出为空
        String param = null;
        Assert.notNull(param, "this parameter must not be null");*/

        /*DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime time = LocalDateTime.now();
        String localTime = df.format(time);
        LocalDateTime ldt = LocalDateTime.parse("2018-01-12 00:15:05", df);
        System.out.println("小时" + ldt.getHour());
        System.out.println("LocalDateTime转成String类型的时间：" + localTime);
        System.out.println("String类型的时间转成LocalDateTime：" + ldt);

        String format = DateTimeFormatter.BASIC_ISO_DATE.format(time);
        System.out.println("-------->" + format);

        LocalDate of = LocalDate.of(2020, 11, 1);
        System.out.println(of.plusDays(-1));*/

        /*System.out.println();
        System.out.println();
        System.out.println();
        System.out.println();
        System.out.println();*/


        /*System.out.println(System.getProperty("user.dir") + "/src/main/resources/script/Main.txt");
        String s = new String(Files.readAllBytes(Paths.get(System.getProperty("user.dir"),
                "/src/main/resources/script/Main.txt")));
        System.out.println(s);*/



       /* ClassPathResource classPathResource = new ClassPathResource("script/Main.txt");
        String path = classPathResource.getPath();
        System.out.println(path);
        String filename = classPathResource.getFilename();
        String s1 = new String(Files.readAllBytes(Paths.get(path)));
        System.out.println(s1);*/

        /*System.out.println (System.getProperty ( "os.name" ));
        int i = 2;
        try {
             i = 1 / 0;
        } catch (Exception e) {
            e.printStackTrace();
            if (i > 0) {
                throw new MyException(SERVER_ERROR);
            } else {
                throw new MyException(BAD_REQUEST);
            }
        }*/

        /*System.out.println(System.getProperty("os.name"));
        Path p = Paths.get("PartsOfPaths.java").toAbsolutePath();
        System.out.println(p);*/

        try (
                Stream<String> input =
                        Files.lines(Paths.get("D:\\IdeaCode\\newcode\\springboot-learn\\src\\main\\java\\com\\frank\\jpaBatchSave\\entity\\Person.java"));
                PrintWriter output =
                        new PrintWriter("StreamInAndOut.txt")
        ) {
            input.map(String::toUpperCase)
                    .forEachOrdered(output::println);
            System.out.println(input.toString());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }


    }
}
